package cn.smbms.service.impl;

import cn.smbms.dao.UserMapper;
import cn.smbms.pojo.User;
import cn.smbms.service.UserService;
import cn.smbms.utils.PageSupport;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User Login(String userCode, String password) {
        try {
            return userMapper.Login(userCode,password);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public User getUserByUserCode(String userCode) {
        try {
            return userMapper.getUserByUserCode(userCode);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public User getUserById(Integer id) {
        try {
            return userMapper.getUserById(id);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public Integer getUserCount(String userName, Integer userRole) {
        try {
            return userMapper.getUserCount(userName,userRole);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public List<User> getUserList(String userName, Integer userRole, PageSupport pageSupport) {
        try {
            return userMapper.getUserList(userName,userRole,pageSupport);
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public Boolean addUser(User user) {
        try {
            return userMapper.addUser(user);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public Boolean deleteUser(Integer userid) {
        try {
            return userMapper.deleteUser(userid);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public Boolean updateUser(User user) {
        try {
            return userMapper.updateUser(user);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public Boolean updateUserPassword(Integer id, String userPassword) {
        try {
            return userMapper.updateUserPassword(id,userPassword);
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
    }
}
